// import path from 'path'
const pathSrc = path.resolve(__dirname, 'src')

import { fileURLToPath, URL } from 'node:url'


import { defineConfig } from 'vite'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
import { env } from 'node:process'
import path from 'node:path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue'],
      resolvers: [ElementPlusResolver()],
      vueTemplate: true, // 是否在 vue 模板中自动导入

    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  envPrefix: ['VITE', 'VUE'],// 环境变量前缀,默认只会暴露VITE开头变量，定义后可暴露VUE开头变量
  resolve: {
    alias: {
      '@': pathSrc
    }
  },
  server: {
    host: '0.0.0.0',
    port: Number(env.VITE_APP_PORT),
    open: true, //运行时是否打开浏览器
    //反向代理解决跨域问题
    proxy: {
      [env.VITE_APP_BASE_API]: {
        target: 'http://lanlu.free.idcfengye.com',//接口地址
        changeOrigin: true,
        rewrite: path =>
          path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
      }
    }

  }
})
